package com.ebupt.migu.music.common.webconfig;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.ebupt.migu.music.common.interceptor.JwtInterceptor;

/**
 * @program: workorder
 * @description: web配置类
 * @author: zhanggk
 * @create: 2019-02-28 14:03
 **/
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private JwtInterceptor jwtInterceptor;

    /**
     * 添加CORS协议，来支持跨域
     *
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**").allowCredentials(true).allowedHeaders("*").allowedOriginPatterns("*")
                .allowedMethods("*");
    }

    /**
     * 添加自定义拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor)
                // 需要拦截的地址
                .addPathPatterns("/**")
                // 不需要拦截的地址
                .excludePathPatterns(
                        "/check", "/reSendSMS", "/modify", "/captcha", "/logout", "/blacklist/exportTemplate",
                        "/whitelist/exportTemplate", "/1/updatenotice.json", "/musiclabel/usercontent", "/musiclabel/send",
                        "/strategy/imageUpload", "/MessagePushController/exportMap", "/MessagePushController/daily/**", "/BannerOpController/exportMap",
                        "/SMSOperationController/exportMap", "/SMSOperationController/daily/**", "/MusicSoundController/exportMap", "/heavyUsers/exportMap",
                        "/effectTotal/exportMap", "/label/refresh", "/label/area", "/upload/imageFile",
                        "/messageNotice/exportMap", "/roster/inverse_search", "/es/existsIndex", "/autoTouchOff/testSend",
                        "/autoTouchOff/testEs", "/autoTouchOff/test", "/strategyTask/pushResult", "/hive2redis/**",
                        "/sound/reco", "/sound/update", "/api/refresh_user_group_size", "/ser/send_message",
                        "/weeklyTotal/export", "/data/success", "/dept/modify", "/customer/detail", "/siginIn/getSiginUserInfo",
                        "/customer/**", "/strategy/**", "/global/action/**", "/global/condition/**",
                        "/global/action/enum/pages", "/global/h5info/**", "/dataArkLogin", "/rxkLogin",
                        "/musiclabel/getUserRelationVal", "/schedule/**", "/strategyTask/synchronizePushResult",
                        "/Megamarket/**", "/strategyTask/synchronizePushResult", "/crowd/queryUserGroupForInsight",
                        "/crowd/downloadUserGroup", "/system/user/syncAccount", "/deleteRedisSpringKey", "/os-cloud/detail",
                        "/autoTouchOff/testRefresh", "/strategy/test", "/test/api/sftp/download", "/test/api/redis",
                        "/autoTri/manual", "/megamarket/qry/conf", "/global/action/qrySettingsByCreator",
                        "/propagate/effect/export", "/propagate/downFile", "/data/happiness/upload", "/scene/labels/**",
                        "/unifyAudit/result/notify", "/market-sms-strategy/**", "/sms/tmpl/**",
                        "/scene/labels/callback", "/approve/**","/issueInfo/**","/provinceSwitch/**"
                );
    }
}
